using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;

using NUnit.Framework;

using DataAccessLayer;

namespace Entities
{
    [TestFixture]
    public class LabelFixture : ConnectionFixture
    {
        private static readonly string lablelName = "Test Label";

        private RecordingDataSet recordingDataSet;
        private LabelGateway gateway;

        private long insertedId;

        [SetUp]
        public void SetUp()
        {
            gateway = new LabelGateway(Connection);
            recordingDataSet = new RecordingDataSet();
            insertedId = gateway.Insert(lablelName, recordingDataSet);
        }



        [TearDown]
        public void TearDown()
        {
            gateway.Delete(insertedId, recordingDataSet);
        }

        [Test]
        public void Retrieve()
        {
            RecordingDataSet.LabelRow row = gateway.FindById(insertedId, new RecordingDataSet());
            Assert.AreEqual(insertedId, row.id);
            Assert.AreEqual(lablelName, row.name);
        }

        [Test]
        public void Delete()
        {
            long deletedId = gateway.Insert("Deleted Label", new RecordingDataSet());
            gateway.Delete(deletedId, recordingDataSet);
            Assert.IsNull(gateway.FindById(deletedId, new RecordingDataSet()));

        }

        [Test]
        public void Update()
        {
            string modifiedName = "Mod Name";
            RecordingDataSet updatedDataSet = new RecordingDataSet();
            RecordingDataSet.LabelRow row = gateway.FindById(insertedId, updatedDataSet);
            row.name = modifiedName;
            gateway.Update(updatedDataSet);
            Assert.AreEqual(modifiedName, gateway.FindById(insertedId, recordingDataSet).name);

        }


    }
}
